def a(n):
    f=True
    for i in range(2*n):
        if n%i==0:
            f = False
            break
    return f
    number = int(input())
    p=0
    if 1000<= number<10000:
        if a(number):
            p=number
        else:
            if a(number//10):
                p=number//10
            if a(number%1000):
                p=max(p, number%1000)
            else:
                if a(number//100):
                    p=max(p,number//100)
                if a(number%100):
                    p=max(p,number%100)
                if a(number%1000//10):
                    p=max(p,number%1000//10)
        print(p)
else:
    print(0)
            
            